* GRUPO XX DE ALGORITMOS Y PROGRAMACION IV (7527).
* FACULTAD DE INGENIERIA DE LA UNIVERSIDAD DE BUENOS AIRES.

* ARCHIVO PARA TODAS LAS DEFINICIONES

	IDENTIFICATION DIVISION.
	PROGRAM-ID. TP-ETAPA1.
	AUTHOR. BASUALDO - CUEVAS - MONTES - ROMERO.

* --------------------------------------------------------------- *

	ENVIRONMENT DIVISION.
	CONFIGURATION SECTION.
	SPECIAL-NAMES.
	    DECIMAL-POINT IS COMMA.

* --------------------------------------------------------------- *

	INPUT-OUTPUT SECTION.
	FILE-CONTROL.

            SELECT RESERVAS-1          ASSIGN TO 'C:\COBOL\Compilado\RESERVAS-1.DAT'
                                       FILE STATUS IS WSS-FS-RES1.

            SELECT RESERVAS-2          ASSIGN TO 'C:\COBOL\Compilado\RESERVAS-2.DAT'
                                        FILE STATUS IS WSS-FS-RES2.

            SELECT RESERVAS-3          ASSIGN TO 'C:\COBOL\Compilado\RESERVAS-3.DAT'
                                        FILE STATUS IS WSS-FS-RES3.

            SELECT RESERVAS-VIP        ASSIGN TO 'C:\COBOL\Compilado\RESERVAS-VIP.DAT'
                                        FILE STATUS IS WSS-FS-VIP.

            SELECT ESTADIAS             ASSIGN TO 'C:\COBOL\Compilado\ESTADIAS.DAT'
                                        FILE STATUS IS WSS-FS-EST.

            SELECT CATEGORIAS          ASSIGN TO 'C:\COBOL\Compilado\CATEGORIAS.DAT'
                                        FILE STATUS IS WSS-FS-CAT.

            SELECT DESCUENTOS          ASSIGN TO 'C:\COBOL\Compilado\DESCUENTOS.DAT'
                                        FILE STATUS IS WSS-FS-DESC.
	
            SELECT MAESTRO              ASSIGN TO 'C:\COBOL\Compilado\MAESTRO.DAT'
                                        FILE STATUS IS WSS-FS-MAESTRO.


            SELECT ARCHIVO-REPORTE ASSIGN TO 'C:\COBOL\Compilado\REPORTE.DAT'
                                        FILE STATUS IS WSS-FS-REPORTE.

            SELECT ARCHIVO-MATRIZ ASSIGN TO 'C:\COBOL\Compilado\MATRIZ.DAT'
                                        FILE STATUS IS WSS-FS-MATRIZ.






* --------------------------------------------------------------- *

	DATA DIVISION.
	FILE SECTION.
	
        FD RESERVAS-1           DATA RECORD IS RES1
				LABEL RECORD IS STANDARD.
        01 REG-RES1.
           05 REG-RES1-CLAVE.
              10 REG-RES1-COD-RES       PIC 9(6).
              10 REG-RES1-DIGITO        PIC 9.
           05 REG-RES1-FECHA-DES.
              10 REG-RES1-ANIO-DES      PIC X(4).
              10 FILLER                   PIC X VALUE '-'.
              10 REG-RES1-MES-DES       PIC X(2).
              10 FILLER                   PIC X VALUE '-'.
              10 REG-RES1-DIA-DES       PIC X(2).
           05 REG-RES1-FECHA-HAS.
              10 REG-RES1-ANIO-HAS      PIC X(4).
              10 FILLER                   PIC X VALUE '-'.
              10 REG-RES1-MES-HAS       PIC X(2).
              10 FILLER                   PIC X VALUE '-'.
              10 REG-RES1-DIA-HAS       PIC X(2).
           05 REG-RES1-CATEG-HAB        PIC 9(4).
           05 REG-RES1-DATOS-PERS.
              10 REG-RES1-NOMBRE-CLI    PIC X(30).
              10 REG-RES1-TEL           PIC X(15).
              10 REG-RES1-DIR           PIC X(30).
           05 REG-RES1-IMP-RES          PIC S9(06)V99.



* *********************************

        FD RESERVAS-2           LABEL RECORD IS STANDARD
                                DATA RECORD IS RES2.

         01 REG-RES2.
            05 REG-RES2-CLAVE.
               10 REG-RES2-COD-RES       PIC 9(6).
               10 REG-RES2-DIGITO        PIC 9.
            05 REG-RES2-FECHA-DES.
               10 REG-RES2-ANIO-DES      PIC X(4).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES2-MES-DES       PIC X(2).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES2-DIA-DES       PIC X(2).
            05 REG-RES2-FECHA-HAS.
               10 REG-RES2-ANIO-HAS      PIC X(4).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES2-MES-HAS       PIC X(2).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES2-DIA-HAS       PIC X(2).
            05 REG-RES2-CATEG-HAB        PIC 9(4).
            05 REG-RES2-DATOS-PERS.
               10 REG-RES2-NOMBRE-CLI    PIC X(30).
               10 REG-RES2-TEL           PIC X(15).
               10 REG-RES2-DIR           PIC X(30).
            05 REG-RES2-IMP-RES          PIC S9(06)V99.


* *********************************

        FD RESERVAS-3           LABEL RECORD IS STANDARD
                                DATA RECORD IS RES3.
         01 REG-RES3.
            05 REG-RES3-CLAVE.
               10 REG-RES3-COD-RES       PIC 9(6).
               10 REG-RES3-DIGITO        PIC 9.
            05 REG-RES3-FECHA-DES.
               10 REG-RES3-ANIO-DES      PIC X(4).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES3-MES-DES       PIC X(2).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES3-DIA-DES       PIC X(2).
            05 REG-RES3-FECHA-HAS.
               10 REG-RES3-ANIO-HAS      PIC X(4).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES3-MES-HAS       PIC X(2).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES3-DIA-HAS       PIC X(2).
            05 REG-RES3-CATEG-HAB        PIC 9(4).
            05 REG-RES3-DATOS-PERS.
               10 REG-RES3-NOMBRE-CLI    PIC X(30).
               10 REG-RES3-TEL           PIC X(15).
               10 REG-RES3-DIR           PIC X(30).
            05 REG-RES3-IMP-RES          PIC S9(06)V99.

* *********************************

        FD RESERVAS-VIP         LABEL RECORD IS STANDARD
                                DATA RECORD IS VIP.

         01 REG-RES-VIP.
            05 REG-RES-VIP-CLAVE.
               10 REG-RES-VIP-COD-RES       PIC 9(6).
               10 REG-RES-VIP-DIGITO        PIC 9.
            05 REG-RES-VIP-FECHA-DES.
               10 REG-RES-VIP-ANIO-DES      PIC X(4).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES-VIP-MES-DES       PIC X(2).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES-VIP-DIA-DES       PIC X(2).
            05 REG-RES-VIP-FECHA-HAS.
               10 REG-RES-VIP-ANIO-HAS      PIC X(4).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES-VIP-MES-HAS       PIC X(2).
               10 FILLER                   PIC X VALUE '-'.
               10 REG-RES-VIP-DIA-HAS       PIC X(2).
            05 REG-RES-VIP-CATEG-HAB        PIC 9(4).
            05 REG-RES-VIP-DATOS-PERS.
               10 REG-RES-VIP-NOMBRE-CLI    PIC X(30).
               10 REG-RES-VIP-TEL           PIC X(15).
               10 REG-RES-VIP-DIR           PIC X(30).
            05 REG-RES-VIP-IMP-RES          PIC S9(06)V99.

* *********************************
	FD ESTADIAS		DATA RECORD IS EST
				LABEL RECORD IS STANDARD.

        01 EST                          PIC X(40).

* *********************************

	FD CATEGORIAS		DATA RECORD IS CAT
				LABEL RECORD IS STANDARD.

        01 CAT                          PIC X(19).

* *********************************
	   
	FD DESCUENTOS		DATA RECORD IS DESC
				LABEL RECORD IS STANDARD.

        01 DESC                         PIC X(13).

* *********************************

	FD MAESTRO		DATA RECORD IS MAE
				LABEL RECORD IS STANDARD.

        01 MAE                          PIC X(116).


* *********************************

        FD  ARCHIVO-REPORTE
                                 DATA RECORD IS REGISTRO-REPORTE.
        01 REGISTRO-REPORTE                    PIC X(101).

* *********************************

        FD  ARCHIVO-MATRIZ
                                 DATA RECORD IS REGISTRO-MATRIZ.
        01 REGISTRO-MATRIZ                     PIC X(811).



* --------------------------------------------------------------- *

	WORKING-STORAGE SECTION.

* ------------------------- CONSTANTES ------------------------- *

        01 CONSTANTES.
           05 WSC-MAX-LINEA            PIC 9(02) VALUE 60.
           05 WSC-N-1                  PIC 9(01) VALUE 1.



* ------------------------- VARIABLES -------------------------- *
        01 TABLA-CATEGORIAS.
           05 WSV-TABLA-CATEGORIAS              OCCURS 10.
              10  WSV-TBL-CAT-HB                PIC 9(4).
              10  WSV-TBL-CAT-DESC              PIC X(15).

        01 WSV-TBL-HLD.
           05  WSV-CAT-HB-HLD                   PIC 9(4).
           05  WSV-CAT-DESC-HLD                 PIC X(15).


        01 VARIABLES.
           05 WSV-MATRIZ-ESTADISTICAS.
              10 WSV-COLUMNA-MESES OCCURS 12 TIMES.
                 15 WSV-FILA-CATEGORIAS OCCURS 50 TIMES.
                    20 WSV-IMPORTE-MATRIZ       PIC 9(09)V99.
        01 WSV-FECHA-DEL-DIA.
           05 WSV-FECHA-DEL-DIA-AAAA PIC X(04).
           05 WSV-FECHA-DEL-DIA-MM   PIC X(02).
           05 WSV-FECHA-DEL-DIA-DD   PIC X(02).



        77 WS-DESC                             PIC S9(06)V9(02).



* ------------------------- INDICES ---------------------------- *

        01 INDICES.
           05 WSI-I                            PIC 9(2) VALUE 1.
           05 WSI-J                            PIC 9(2) VALUE 1.
           05 WSI-SUB                          PIC 9(2) VALUE 1.

           05 WSI-X                            PIC 9(2) VALUE 1.
           05 WSI-Y                            PIC 9(2) VALUE 1.
           05 WSI-MES                          PIC 9(2).
           05 WSI-CATEGORIA                    PIC 9(2).
           05 WSI-LINEA                        PIC 9(2).
           05 WSI-PAGINA                       PIC 9(04).



* ------------------------- SWHITCHES -------------------------- *
        01 SWITCHES.
           05 WSS-FS-RES1                      PIC X(2).

           05 WSS-FS-RES2                      PIC X(2).

           05 WSS-FS-RES3                      PIC X(2).

           05 WSS-FS-VIP                       PIC X(2).

           05 WSS-FS-EST                       PIC X(2).

           05 WSS-FS-CAT                       PIC X(2).

           05 WSS-FS-DESC                      PIC X(2).

           05 WSS-FS-MAESTRO                   PIC X(2).

           05 WSS-FS-EOF-RES1                  PIC X(2)   VALUE 'NO'.
           05 WSS-FS-EOF-RES2                  PIC X(2)   VALUE 'NO'.
           05 WSS-FS-EOF-RES3                  PIC X(2)   VALUE 'NO'.
           05 WSS-FS-EOF-VIP                   PIC X(2)   VALUE 'NO'.
           05 WSS-FS-EOF-EST                   PIC X(2)   VALUE 'NO'.
           05 WSS-FS-EOF-CAT                   PIC X(2)   VALUE 'NO'.
           05 WSS-FS-EOF-DESC                  PIC X(2)   VALUE 'NO'.

           05  WSS-FS-REPORTE                  PIC 9(2) .
              88 WSS-FS-REPORTE-OK               VALUE 00.
              88 WSS-FS-REPORTE-FIN              VALUE 10.

           05  WSS-FS-MATRIZ                   PIC 9(2) .
              88 WSS-FS-MATRIZ-OK                VALUE 00.
              88 WSS-FS-MATRIZ-FIN               VALUE 10.


* ---------------------------------
* ***** LA CLAVE MENOR *****
        01 WS-MENOR.
           05 WS-MENOR-COD-RES            PIC 9(6).
           05 WS-MENOR-DIGITO             PIC 9.


* ------------------------- REGISTROS -------------------------- *


        01 WS-REG-EST.
           05 WS-REG-EST-CLAVE.
              10 WS-REG-EST-COD-RES       PIC 9(6).
              10 WS-REG-EST-DIGITO        PIC 9.
           05 WS-REG-EST-FECHA-DES.
              10 WS-REG-EST-ANIO-DES      PIC X(4).
              10 FILLER                   PIC X VALUE '-'.
              10 WS-REG-EST-MES-DES       PIC X(2).
              10 FILLER                   PIC X VALUE '-'.
              10 WS-REG-EST-DIA-DES       PIC X(2).
           05 WS-REG-EST-FECHA-HAS.
              10 WS-REG-EST-ANIO-HAS      PIC X(4).
              10 FILLER                   PIC X VALUE '-'.
              10 WS-REG-EST-MES-HAS       PIC X(2).
              10 FILLER                   PIC X VALUE '-'.
              10 WS-REG-EST-DIA-HAS       PIC X(2).
           05 WS-REG-EST-CATEG-HAB        PIC 9(4).
           05 WS-REG-EST-IMPORTE          PIC S9(06)V9(2).

* -----------------------

        01 WS-REG-DESC.
           05 WS-REG-DESC-CLAVE.
              10 WS-REG-DESC-COD-RES      PIC 9(6).
              10 WS-REG-DESC-DIG          PIC 9.
           05 WS-REG-DESC-PORC            PIC 9(3)V9(2).

* -----------------------

        01 WS-REG-MAE.
           05 WS-REG.
              10 WS-REG-MAE-CLAVE.
                 15 WS-REG-MAE-COD-RES       PIC 9(6).
                 15 WS-REG-MAE-DIGITO        PIC 9.
              10 WS-REG-MAE-FECHA-DES.
                 15 WS-REG-MAE-ANIO-DES      PIC X(4).
                 15 FILLER                   PIC X VALUE '-'.
                 15 WS-REG-MAE-MES-DES       PIC X(2).
                 15 FILLER                   PIC X VALUE '-'.
                 15 WS-REG-MAE-DIA-DES       PIC X(2).
              10 WS-REG-MAE-FECHA-HAS.
                 15 WS-REG-MAE-ANIO-HAS      PIC X(4).
                 15 FILLER                   PIC X VALUE '-'.
                 15 WS-REG-MAE-MES-HAS       PIC X(2).
                 15 FILLER                   PIC X VALUE '-'.
                 15 WS-REG-MAE-DIA-HAS       PIC X(2).
              10 WS-REG-MAE-CATEG-HAB        PIC 9(4).
              10 WS-REG-MAE-DATOS-PERS.
                 15 WS-REG-MAE-NOMBRE-CLI    PIC X(30).
                 15 WS-REG-MAE-TEL           PIC X(15).
                 15 WS-REG-MAE-DIR           PIC X(30).
              10 WS-REG-MAE-IMP              PIC S9(06)V99.
           05 WS-REG-MAE-ESTADO           PIC X.


* --------------------------

        01 WS-REG-CAT.
           03 WS-REG-CAT-HAB              PIC 9(4).
           03 WS-REG-CAT-DESCRIP          PIC X(15).

* --------------------------

        01  REGISTRO-ARCHIVO-REPORTE.
           05 WSV-LINEA-UNO.
              10 FILLER                    PIC X(07) VALUE 'FECHA: '.
              10 WSV-FECHA-LISTADO-RESERVAS.
                 15 WSV-FEC-LISTADO-RESERVAS-AAAA PIC X(04).
                 15 FILLER                        PIC X(01) VALUE '/'.
                 15 WSV-FEC-LISTADO-RESERVAS-MM  PIC X(02).
                 15 FILLER                       PIC X(01) VALUE '/'.
                 15 WSV-FEC-LISTADO-RESERVAS-DD  PIC X(02).

              10 FILLER                         PIC X(79) VALUE SPACES.
              10 WSV-HOJA-NRO.

                 15 FILLER                 PIC X(10) VALUE 'HOJA NRO: '.
                 15 WSV-NUMERO-HOJA               PIC ZZ.
           05 WSV-SEPARADO-UNO             PIC X(80) VALUE SPACES.
           05 WSV-LINEA-DOS.

              10 FILLER                        PIC X(41) VALUE SPACES.
              10 FILLER           PIC X(19) VALUE 'LISTADO DE ESTADIAS'.
              10 FILLER                   PIC X(41) VALUE SPACES.
           05 WSV-LINEA-TRES.

             10 FILLER                      PIC X(07) VALUE 'COD RES'.
             10 FILLER                      PIC X(01) VALUE SPACES.
             10 FILLER                      PIC X(03) VALUE 'DIG'.
             10 FILLER                      PIC X(01) VALUE SPACES.
             10 FILLER                     PIC X(10) VALUE 'FEC. DESDE'.
             10 FILLER                     PIC X(01) VALUE SPACES.
             10 FILLER                     PIC X(10) VALUE 'FEC. HASTA'.
             10 FILLER                      PIC X(04) VALUE SPACES.
             10 FILLER                      PIC X(09) VALUE 'CATEGORIA'.
             10 FILLER                      PIC X(06) VALUE SPACES.
             10 FILLER                      PIC X(07) VALUE 'IMPORTE'.
             10 FILLER                      PIC X(12) VALUE SPACES.
             10 FILLER                 PIC X(30) VALUE 'NOMBRE CLIENTE'.

          05 WSV-LINEA-CUATRO.
             10 WSV-CODIGO                       PIC X(06).
             10 FILLER                           PIC X(01) VALUE SPACES.
             10 WSV-DIGITO                       PIC X(01).
             10 FILLER                           PIC X(01) VALUE SPACES.
             10 WSV-FEC-DES                      PIC X(10).
             10 FILLER                           PIC X(01) VALUE SPACES.
             10 WSV-FEC-HAS                      PIC X(10).
             10 FILLER                           PIC X(01) VALUE SPACES.
             10 WSV-CATEGORIA                    PIC X(15).
             10 FILLER                           PIC X(01) VALUE SPACES.
             10 WSV-IMPORTE                      PIC $$$.$$9,99.
             10 FILLER                           PIC X(01) VALUE SPACES.
             10 WSV-NOMB-CLIE                    PIC X(30).

       01  REGISTRO-ARCHIVO-MATRIZ.
          05 WSV-LINEA-0.
             10 FILLER                  PIC X(15) VALUE ALL '#'.
             10 WSV-CABECERA-MATRIZ OCCURS 50 TIMES.

                15 WSV-CATEGORIA-SALIDA             PIC X(15).
                15 FILLER                           PIC X(01) VALUE '|'.
          05 WSV-LINEA-1.
             10 FILLER                         PIC X(10) VALUE 'ENERO'.
             10 WSV-ESTADISTICAS-ENE OCCURS 50 TIMES.
                 15 WSV-VALOR-EST-ENE           PIC $$$.$$$.$$9,99.
                 15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-2.
             10 FILLER                        PIC X(10) VALUE 'FEBRERO'.
               10 WSV-ESTADISTICAS-FEB OCCURS 50 TIMES.
                  15 WSV-VALOR-EST-FEB           PIC $$$.$$$.$$9,99.
                  15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-3.
             10 FILLER                         PIC X(10) VALUE 'MARZO'.
               10 WSV-ESTADISTICAS-MAR OCCURS 50 TIMES.
                  15 WSV-VALOR-EST-MAR           PIC $$$.$$$.$$9,99.
                  15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-4.
             10 FILLER                         PIC X(10) VALUE 'ABRIL'.
               10 WSV-ESTADISTICAS-ABR OCCURS 50 TIMES.
                  15 WSV-VALOR-EST-ABR           PIC $$$.$$$.$$9,99.
                  15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-5.
             10 FILLER                           PIC X(10) VALUE 'MAYO'.
             10 WSV-ESTADISTICAS-MAY OCCURS 50 TIMES.
                 15 WSV-VALOR-EST-MAY           PIC $$$.$$$.$$9,99.
                 15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-6.
             10 FILLER                         PIC X(10) VALUE 'JUNIO'.
             10 WSV-ESTADISTICAS-JUN OCCURS 50 TIMES.
                 15 WSV-VALOR-EST-JUN           PIC $$$.$$$.$$9,99.
                 15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-7.
             10 FILLER                         PIC X(10) VALUE 'JULIO'.
             10 WSV-ESTADISTICAS-JUL OCCURS 50 TIMES.
                 15 WSV-VALOR-EST-JUL           PIC $$$.$$$.$$9,99.
                 15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-8.
             10 FILLER                         PIC X(10) VALUE 'AGOSTO'.
             10 WSV-ESTADISTICAS-AGO OCCURS 50 TIMES.
                 15 WSV-VALOR-EST-AGO           PIC $$$.$$$.$$9,99.
                 15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-9.
             10 FILLER                     PIC X(10) VALUE 'SEPTIEMBRE'.
             10 WSV-ESTADISTICAS-SEP OCCURS 50 TIMES.
                 15 WSV-VALOR-EST-SEP           PIC $$$.$$$.$$9,99.
                 15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-10.
             10 FILLER                        PIC X(10) VALUE 'OCTUBRE'.
             10 FILLER                      PIC X(10) VALUE 'NOVIEMBRE'.
             10 WSV-ESTADISTICAS-OCT OCCURS 50 TIMES.
                 15 WSV-VALOR-EST-OCT           PIC $$$.$$$.$$9,99.
                 15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-11.
             10 WSV-ESTADISTICAS-NOV OCCURS 50 TIMES.
                 15 WSV-VALOR-EST-NOV           PIC $$$.$$$.$$9,99.
                 15 FILLER                      PIC X(01) VALUE '|'.
          05 WSV-LINEA-12.
             10 FILLER                      PIC X(10) VALUE 'DICIEMBRE'.
             10 WSV-ESTADISTICAS-DIC OCCURS 50 TIMES.
                 15 WSV-VALOR-EST-DIC          PIC $$$.$$$.$$9,99.
                 15 FILLER                     PIC X(01) VALUE '|'.



* -------------------------------------------------------------- *

		
        PROCEDURE DIVISION.
	GENERAL.
	
           PERFORM INICIO.
           PERFORM LECTURA-INICIAL.
           PERFORM CARGA-Y-ORDENA-TAB-CAT.
           PERFORM PROCESO UNTIL WSS-FS-EOF-VIP = 'SI'
                                AND WSS-FS-EOF-RES1 = 'SI'
                                AND WSS-FS-EOF-RES2 = 'SI'
                                AND WSS-FS-EOF-RES3 = 'SI'.
           PERFORM FIN.
           STOP RUN.
	
	
* ***************************  INICIO  ***************************
	INICIO.

           PERFORM 1XXXXX-GRABAR-CABECERA-REPORTE.
           PERFORM 41X000-ABRIR-ARCHIVO-REPORTE.
           PERFORM 41X000-ABRIR-ARCHIVO-MATRIZ.

           OPEN INPUT RESERVAS-1.
           IF WSS-FS-RES1 NOT = ZERO
              DISPLAY 'ERROR EN OPEN, FS: ' WSS-FS-RES1
              STOP RUN.

           OPEN INPUT RESERVAS-2.
           IF WSS-FS-RES2 NOT = ZERO
              DISPLAY 'ERROR EN OPEN, FS: ' WSS-FS-RES2
              STOP RUN.

           OPEN INPUT RESERVAS-3.
           IF WSS-FS-RES3 NOT = ZERO
              DISPLAY 'ERROR EN OPEN, FS: ' WSS-FS-RES3
              STOP RUN.

           OPEN INPUT RESERVAS-VIP.
           IF WSS-FS-VIP NOT = ZERO
              DISPLAY 'ERROR EN OPEN, FS: ' WSS-FS-VIP
              STOP RUN.

           OPEN INPUT ESTADIAS.
           IF WSS-FS-EST NOT = ZERO
              DISPLAY 'ERROR EN OPEN, FS: ' WSS-FS-EST
              STOP RUN.


           OPEN OUTPUT MAESTRO.

* ********************** OPEN ARCHIVOS REPORTES ******************

        41X000-ABRIR-ARCHIVO-MATRIZ.
           OPEN INPUT ARCHIVO-MATRIZ.

        41X000-ABRIR-ARCHIVO-REPORTE.
           OPEN INPUT ARCHIVO-REPORTE.


* *************************  LECTURA-INICIAL  ********************
	LECTURA-INICIAL.
            PERFORM 421000-LEO-RES1.
            PERFORM 422000-LEO-RES2.
            PERFORM 423000-LEO-RES3.
            PERFORM 424000-LEO-VIP.
            PERFORM 425000-LEO-EST.
            PERFORM 426000-LEO-CAT.
            PERFORM 427000-LEO-DESC.
	
* *************************** LEO-RES1 ***************************
        421000-LEO-RES1.
           READ RESERVAS-1
              AT END MOVE 'SI' TO WSS-FS-EOF-RES1.

           IF WSS-FS-RES1 NOT = ZERO AND 10
              DISPLAY 'ERROR EN READ FS: ' WSS-FS-RES1
              STOP RUN.
* *************************** LEO-RES2 ***************************
        422000-LEO-RES2.
           READ RESERVAS-2
           AT END MOVE 'SI' TO WSS-FS-EOF-RES2.

           IF WSS-FS-RES2 NOT = ZERO AND 10
              DISPLAY 'ERROR EN READ FS: ' WSS-FS-RES2
              STOP RUN.
* *************************** LEO-RES3 ***************************
        423000-LEO-RES3.
           READ RESERVAS-3
           AT END MOVE 'SI' TO WSS-FS-EOF-RES3.

           IF WSS-FS-RES3 NOT = ZERO AND 10
              DISPLAY 'ERROR EN READ FS: ' WSS-FS-RES3
              STOP RUN.

* *************************** LEO-VIP ****************************
        424000-LEO-VIP.
           READ RESERVAS-VIP
           AT END MOVE 'SI' TO WSS-FS-EOF-VIP.

           IF WSS-FS-VIP NOT = ZERO AND 10
              DISPLAY 'ERROR EN READ FS: ' WSS-FS-VIP
              STOP RUN.

* *************************** LEO-EST ***************************
        425000-LEO-EST.
           READ ESTADIAS
           AT END MOVE 'SI' TO WSS-FS-EOF-EST.
           MOVE EST TO WS-REG-EST.

           IF WSS-FS-EST NOT = ZERO AND 10
              DISPLAY 'ERROR EN READ FS: ' WSS-FS-EST
              STOP RUN.

* **************************** LEO-CAT ***************************
        426000-LEO-CAT.
           READ CATEGORIAS
           AT END MOVE 'SI' TO WSS-FS-EOF-CAT.
           MOVE CAT TO WS-REG-CAT.

           IF WSS-FS-CAT NOT = ZERO AND 10
              DISPLAY 'ERROR EN READ FS: ' WSS-FS-CAT
              STOP RUN.

* **************************** LEO-DESC **************************
        427000-LEO-DESC.
           READ DESCUENTOS
           AT END MOVE 'SI' TO WSS-FS-EOF-DESC.
           MOVE DESC TO WS-REG-DESC.

           IF WSS-FS-DESC NOT = ZERO AND 10
              DISPLAY 'ERROR EN READ FS: ' WSS-FS-DESC
              STOP RUN.

* **********************  CARGA-Y-ORDENA-TAB-CAT *****************
	CARGA-Y-ORDENA-TAB-CAT.
           PERFORM 411000-ABRIR-ARCHIVO-CATEGORIAS.
           PERFORM 426000-LEO-CAT.
           PERFORM 500000-CARGAR-TABLA UNTIL WSS-FS-EOF-CAT = 'SI'
                                             OR WSI-SUB > 50.
           PERFORM 600000-ORDENAR-TABLA-CATEGORIAS.
           PERFORM 431000-CERRAR-ARCH-CATEGORIAS.

        411000-ABRIR-ARCHIVO-CATEGORIAS.
           OPEN INPUT CATEGORIAS.


        500000-CARGAR-TABLA.
           MOVE CAT TO WSV-TABLA-CATEGORIAS(WSI-SUB)
           ADD 1 TO WSI-SUB.
           PERFORM 426000-LEO-CAT.

        600000-ORDENAR-TABLA-CATEGORIAS.
           PERFORM VARYING WSI-I FROM 1 BY 1 UNTIL WSI-I = WSI-SUB + 1
              PERFORM VARYING WSI-J FROM WSI-I BY 1 UNTIL
                                                       WSI-J > WSI-SUB
                 IF WSV-TBL-CAT-HB(WSI-J) < WSV-TBL-CAT-HB(WSI-I) THEN
                    MOVE WSV-TABLA-CATEGORIAS(WSI-I)  TO WSV-TBL-HLD
                    MOVE WSV-TABLA-CATEGORIAS(WSI-J)  TO
                                            WSV-TABLA-CATEGORIAS(WSI-I)
                    MOVE WSV-TBL-HLD TO WSV-TABLA-CATEGORIAS(WSI-J)
                 END-IF
              END-PERFORM
           END-PERFORM.

        431000-CERRAR-ARCH-CATEGORIAS.
           CLOSE CATEGORIAS.


* ****************************  FIN  *****************************
	FIN.
            CLOSE RESERVAS-1 RESERVAS-2 RESERVAS-3 RESERVAS-VIP.
            CLOSE ESTADIAS DESCUENTOS MAESTRO.
            CLOSE ARCHIVO-REPORTE.
            CLOSE ARCHIVO-MATRIZ.


* *************************** PROCESO ****************************
	PROCESO.
	    PERFORM DETERMINAR-MENOR.
	    PERFORM POSIBLE-RES-N.
	    PERFORM POSIBLE-RES-VIP.
	    PERFORM CHEQUEAR-ESTADIA.
	    PERFORM APLICAR-DESCUENTO.
	    PERFORM GRABAR-EN-MAESTRO.
	    PERFORM PROCESAR-REPORTE-ACEPTADA.
	    
* *************************** DETERMINAR-MENOR *******************
	DETERMINAR-MENOR.
               MOVE REG-RES-VIP-CLAVE TO WS-MENOR
               IF WS-MENOR > REG-RES1-CLAVE
                   MOVE REG-RES1-CLAVE TO WS-MENOR
               IF WS-MENOR > REG-RES2-CLAVE
                   MOVE REG-RES2-CLAVE TO WS-MENOR
               IF WS-MENOR > REG-RES3-CLAVE
                   MOVE REG-RES3-CLAVE TO WS-MENOR.

* ************************** POSIBLE-RES-VIP *********************
	POSIBLE-RES-VIP.
           IF WS-MENOR = REG-RES-VIP-CLAVE
              PERFORM OBTENER-ULTIMA-MODIF-VIP UNTIL
              WS-MENOR NOT = REG-RES-VIP-CLAVE OR WSS-FS-EOF-VIP = 'SI'
              MOVE 'N' TO WS-REG-MAE-ESTADO
              MOVE 'N' TO WS-REG-MAE-ESTADO
              IF WSS-FS-EOF-VIP = 'SI'
                 MOVE 9999 TO REG-RES-VIP-COD-RES
                 MOVE 9    TO REG-RES-VIP-DIGITO.


* ********************** OBTENER-ULTIMA-MODIF-VIP ****************
        OBTENER-ULTIMA-MODIF-VIP.
           MOVE REG-RES-VIP TO WS-REG.
           PERFORM 424000-LEO-VIP.

* *************************** POSIBLE-RES-N **********************
        POSIBLE-RES-N.
           PERFORM POSIBLE-RES-1.
           PERFORM POSIBLE-RES-2.
           PERFORM POSIBLE-RES-3.

* *************************** POSIBLE-RES-1 **********************
        POSIBLE-RES-1.
           IF WS-MENOR = REG-RES1-CLAVE
              PERFORM OBTENER-ULTIMA-MODIF-RES1 UNTIL
              WS-MENOR NOT = REG-RES1-CLAVE OR WSS-FS-EOF-RES1 = 'SI'
              MOVE 'N' TO WS-REG-MAE-ESTADO
              IF WSS-FS-EOF-RES1 = 'SI'
                 MOVE 9999 TO REG-RES1-COD-RES
                 MOVE 9    TO REG-RES1-DIGITO.

* ********************** OBTENER-ULTIMA-MODIF-RES1 ***************
        OBTENER-ULTIMA-MODIF-RES1.
           MOVE REG-RES1 TO WS-REG.
           PERFORM 421000-LEO-RES1.

* *************************** POSIBLE-RES-2 **********************
        POSIBLE-RES-2.
           IF WS-MENOR = REG-RES2-CLAVE
              PERFORM OBTENER-ULTIMA-MODIF-RES2
              MOVE 'N' TO WS-REG-MAE-ESTADO
              IF WSS-FS-EOF-RES2 = 'SI'
                 MOVE 9999 TO REG-RES2-COD-RES
                 MOVE 9    TO REG-RES2-DIGITO.

* ********************** OBTENER-ULTIMA-MODIF-RES2 ***************
        OBTENER-ULTIMA-MODIF-RES2.
           MOVE REG-RES2 TO WS-REG.
           PERFORM 422000-LEO-RES2.

* *************************** POSIBLE-RES-3 **********************
        POSIBLE-RES-3.
           IF WS-MENOR = REG-RES3-CLAVE
              PERFORM OBTENER-ULTIMA-MODIF-RES3
              MOVE 'N' TO WS-REG-MAE-ESTADO
              IF WSS-FS-EOF-RES3 = 'SI'
                 MOVE 9999 TO REG-RES3-COD-RES
                 MOVE 9    TO REG-RES3-DIGITO.

* ********************** OBTENER-ULTIMA-MODIF ********************
        OBTENER-ULTIMA-MODIF-RES3.
           MOVE REG-RES3 TO WS-REG.
           PERFORM 423000-LEO-RES3.

* ************************** CHEQUEAR-ESTADIA ********************
	CHEQUEAR-ESTADIA.
           PERFORM 425000-LEO-EST UNTIL WS-MENOR <= WS-REG-EST-CLAVE
                                        OR WSS-FS-EOF-EST = 'SI'.
           IF WS-MENOR = WS-REG-EST-CLAVE
              MOVE WS-REG-EST-FECHA-DES TO WS-REG-MAE-FECHA-DES
              MOVE WS-REG-EST-FECHA-HAS TO WS-REG-MAE-FECHA-HAS
              MOVE WS-REG-EST-CATEG-HAB TO WS-REG-MAE-CATEG-HAB
              ADD WS-REG-EST-IMPORTE TO WS-REG-MAE-IMP
              MOVE 'A' TO WS-REG-MAE-ESTADO.

* ************************** APLICAR-DESCUENTO *******************
	APLICAR-DESCUENTO.
            IF WS-MENOR = WS-REG-DESC-CLAVE
               COMPUTE WS-DESC = (WS-REG-MAE-IMP * 100)/
               WS-REG-DESC-PORC
               SUBTRACT WS-DESC FROM WS-REG-MAE-IMP
               PERFORM 427000-LEO-DESC.
	
* ************************** GRABAR-EN-MAESTRO *******************
	GRABAR-EN-MAESTRO.
	    MOVE WS-REG-MAE TO MAE.
	    WRITE MAE.

* *********************** PROCESAR-REPORTE-ACEPTADA **************
	PROCESAR-REPORTE-ACEPTADA.
            IF WS-REG-MAE-ESTADO = 'A'
*        PERFORM CARGAR-REPORTE-LISTADO
*        PERFORM CARGAR-REPORTE-ESTADISTICAS.
               PERFORM 2XXXXX-CARGAR-REPORTE
               PERFORM 42X000-GRABAR-REPORTE
               PERFORM 2XXXXX-CARGAR-MATRIZ
               PERFORM 3XXXXX-PREPARA-MATRIZ.

* ******************
        42X000-GRABAR-REPORTE.
           WRITE REGISTRO-REPORTE.
           EVALUATE TRUE
              WHEN WSS-FS-REPORTE-OK
                  CONTINUE
              WHEN OTHER
                  PERFORM 999999-ERROR
           END-EVALUATE.


* ******************
        2XXXXX-CARGAR-MATRIZ.
           MOVE WS-REG-MAE-MES-DES    TO WSI-X.
           MOVE WSV-TBL-CAT-HB(WSI-I) TO WSI-Y.
           ADD WS-REG-MAE-IMP TO WSV-IMPORTE-MATRIZ(WSI-X,WSI-Y).

* *******************
        1XXXXX-GRABAR-CABECERA-REPORTE.
           MOVE WSV-FECHA-DEL-DIA-AAAA TO WSV-FEC-LISTADO-RESERVAS-AAAA.
           MOVE WSV-FECHA-DEL-DIA-MM    TO WSV-FEC-LISTADO-RESERVAS-MM.
           MOVE WSV-FECHA-DEL-DIA-DD    TO WSV-FEC-LISTADO-RESERVAS-DD.
           MOVE WSI-PAGINA              TO WSV-NUMERO-HOJA.
           MOVE WSV-LINEA-UNO           TO REGISTRO-REPORTE.
           PERFORM 42x000-GRABAR-REPORTE.
           MOVE WSV-LINEA-DOS           TO REGISTRO-REPORTE.
           PERFORM 42x000-GRABAR-REPORTE.
           MOVE WSV-LINEA-TRES          TO REGISTRO-REPORTE.
           PERFORM 42x000-GRABAR-REPORTE.

        2XXXXX-CARGAR-REPORTE.
           IF WSI-LINEA > WSC-MAX-LINEA THEN
              ADD WSC-N-1 TO WSI-PAGINA
              MOVE WSC-N-1              TO WSI-LINEA
              PERFORM 1XXXXX-GRABAR-CABECERA-REPORTE
           ELSE
              MOVE WS-REG-MAE-COD-RES                  TO WSV-CODIGO
              MOVE WS-REG-MAE-DIGITO                   TO WSV-DIGITO
              MOVE WS-REG-MAE-FECHA-DES                TO WSV-FEC-DES
              MOVE WS-REG-MAE-FECHA-HAS                TO WSV-FEC-HAS
              MOVE WSV-TBL-CAT-DESC(WSI-I)      TO WSV-CATEGORIA
              MOVE WS-REG-MAE-IMP                  TO WSV-IMPORTE
              MOVE WS-REG-MAE-NOMBRE-CLI               TO WSV-NOMB-CLIE
              MOVE WSV-LINEA-CUATRO             TO REGISTRO-REPORTE
              PERFORM 42x000-GRABAR-REPORTE.

* ***********************

        3XXXXX-PREPARA-MATRIZ.
           PERFORM VARYING WSI-I FROM 1 BY 1 UNTIL WSI-I > 50
             MOVE WSV-TBL-CAT-DESC(WSI-I) TO WSV-CATEGORIA-SALIDA(WSI-I)
           END-PERFORM
           MOVE WSV-LINEA-0    TO REGISTRO-MATRIZ.
           PERFORM 42X000-GRABAR-MATRIZ.

           PERFORM VARYING WSI-I FROM 1 BY 1 UNTIL WSI-I > 50

           MOVE WSV-IMPORTE-MATRIZ (1,WSI-I) TO WSV-VALOR-EST-ENE(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (2,WSI-I) TO WSV-VALOR-EST-FEB(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (3,WSI-I) TO WSV-VALOR-EST-MAR(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (4,WSI-I) TO WSV-VALOR-EST-ABR(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (5,WSI-I) TO WSV-VALOR-EST-MAY(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (6,WSI-I) TO WSV-VALOR-EST-JUN(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (7,WSI-I) TO WSV-VALOR-EST-JUL(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (8,WSI-I) TO WSV-VALOR-EST-AGO(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (9,WSI-I) TO WSV-VALOR-EST-SEP(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (10,WSI-I)
                                             TO WSV-VALOR-EST-OCT(WSI-I)
           MOVE WSV-IMPORTE-MATRIZ (11,WSI-I)
                                             TO WSV-VALOR-EST-NOV(WSI-I)

           MOVE WSV-IMPORTE-MATRIZ (12,WSI-I)
                                             TO WSV-VALOR-EST-DIC(WSI-I)

           END-PERFORM
           MOVE WSV-LINEA-1    TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-2     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-3     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-4     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-5     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-6     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-7     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-8   TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-9     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-10     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-11     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ
           MOVE WSV-LINEA-12     TO REGISTRO-MATRIZ
           PERFORM 42X000-GRABAR-MATRIZ.

* ******************
        42X000-GRABAR-MATRIZ.
           WRITE REGISTRO-MATRIZ.
           EVALUATE TRUE
           WHEN WSS-FS-MATRIZ-OK
               CONTINUE
           WHEN OTHER
               PERFORM 999999-ERROR
           END-EVALUATE.
* ******************
        999999-ERROR.
           STOP RUN.

